<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
	<html>

	<head>
		<meta charset="utf-8">
		<title>公益活动</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta http-equiv="Access-Control-Allow-Origin" content="*">
		<meta http-equiv="content-security-policy">
		<link href="css/myui.css" rel="stylesheet" />
		<link href="css/user.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/mui.min.css">
		<link href="font-awesome/css/font-awesome.css" rel="stylesheet" />
		<script src="js/replace.js"></script>
		<script src="js/js/binaryajax.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/js/exif.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/js/canvasResize.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/mui.min.js"></script>
		<script src="js/my.js"></script>
		<script type="text/javascript" src="js/jquery-1.9.0.js" charset="utf-8"></script>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=DIEpModxX0HrT2t10ZtF8z0apw9uDjaT" charset="utf-8"></script>
		<script type="text/javascript" charset="utf-8">
			mui.init();
		</script>
		
		<style type="text/css">
			.mui-table-view:after,.mui-table-view:before{
				height: 0;
			}
			._content{
				/*margin-top: 3rem;*/
			    position: relative;
			    margin-bottom: 4.5rem;
			}
			.useful_camera_a{
				display: block;
				height: 13rem;
			}
			.useful_camera_a>img{
				width: 100%;
				height: 100%;
			}
			.main{
				width: 90%;
    			margin: 0 auto;
    			position: relative;
    			overflow: hidden;
			}
			.wh_activity_contents{
				position: relative;
				overflow: hidden;
				margin-top: 1rem;
				height: 2.55rem;
			    border: 1px solid #f0f2f5;
			}
			.wh_activity_contents>div{
				width: 30%;
				float: left;
				padding: 0.6rem;
				font-size: 1rem;
				background: #f0f2f5;
			}
			.wh_activity_contents>input,#myAddress{
				width: 70%;
				float: left;
				margin: 0;
				font-size: 1rem;
				padding: 0;
				border: none;
				height: auto;
				padding: 0.6rem;
			}
			#myAddress{
				font-size: 0.8rem;
			}
			.mui-bar .mui-btn-link {
			    color: #fff;
			}
			.mui-title{
				color: #fff;
			    height: 3rem;
			    line-height: 3rem;
			    font-size: 1rem;
			}
		</style>
	</head>

	<body style="background: #fff;">
		<div id="app" class="mui-views" data-view="1">
			<div class="mui-view">
				<div class="mui-navbar">
					<div class="mui-navbar-inner mui-bar mui-bar-nav mui-navbar-center">
						<button type="button" class="mui-left mui-action-back mui-btn  mui-btn-link mui-btn-nav mui-pull-left mui-pull-left_style">
							<span class="mui-icon mui-icon-left-nav"></span>
						</button>
						<h1 class="mui-center mui-title mui-title_fff" style="margin-left: -15px;">我的公益活动</h1>
					</div>
				</div>
				<div class="mui-pages">
					<div id="setting" class="mui-page mui-page-center">
			<!--页面主内容区结束-->
					</div>
				</div>
			</div>
		</div>

		<div id="allmap"></div>
		<div class="_content">
			<a href="camera.html" style="" class="useful_camera_a"> <img id="chosedImage" src="img/gongyi_back.png" / height="100px" width="100px"> </a>
			<div class="main">
				<div class="wh_activity_contents">
					<div>位置明细</div>
					<p id="myAddress"></p>
					<input type="text" placeholder="" id="locationDetail" />
				</div>
				<div class="wh_activity_contents">
					<div>活动名称</div> 
					<input type="text" value="" id="activityName" placeholder="请输入活动名称" />
				</div>
				<div class="wh_activity_contents">
					<div>活动人数</div> 
					<input type="tel" value="" id="players" placeholder="请输入活动人数" />
				</div>
				<div class="wh_activity_contents">
					<div>我要发言</div> 
					<input type="text" placeholder="" id="note" /> 
				</div>
			</div>
			<center style="margin-top: 1.5rem;">
				<p id="confirm" class="btn btn_on" style="width: 90%;">签到</p>
			</center>
		</div>
		
		<!---底部-->

		<div class="footer1">
			<a class="wh_footer1_a" id="home">
				<li>
					<p style=""><img src="img/wh_home12.png"></p>
					<p style="color: #fff;">首页</p>
				</li>
			</a>
			<a class="wh_footer1_a" id="welfare">
				<li>
					<p><img src="img/wh_home14.png"></p>
					<p style="color: #fff;">公益活动</p>
					<img src="img/footer_center.png" class="footer_center_yuan">
				</li>
			</a>
			<a class="wh_footer1_a" id="user">
				<li>
					<p><img src="img/wh_home13.png"></p>
					<p style="color: #fff;">我的</p>
				</li>
			</a>
		</div>

		<script src="js/index.js"></script>
		<script src="js/mui.min.js"></script>
		<script>
			
			//打开首页
			localtionURL("home","home.html");
			//打开公益
			localtionURL("wh_camera","wh_camera.html");
			//打开个人
			localtionURL("user","user.html");
			
			var phoneNum = "";
			var picture = new Array();
			var imgurl = "",
				address = "",
				name = "",
				lon = "",
				lat = "";
			var isOpenGps = false;
			mui.plusReady(function() {});
			$("#allmap").hide();
			$("#confirm").click(function() {
				compress(imgurl);
			});
			$('#back').click(function() {
				Location.href = "home.html";
			});
			$(function() {
				mui.plusReady(function() {
					if ($("#myAddress").text() == '' || $("#myAddress").text() == null) {
						getGEO_status();
					}
					phoneNum = localStorage.getItem("phoneNum");
					if (phoneNum == "" || phoneNum == null) {
						mui.toast("请先登录！");
						location.href = "login.html";
					}
				});
			});
			$(function() {
				var GetRequest = function(url) {
					//获取url，获取id的方法
					var url = location.search; //获取url中"?"符后的字串
					var theRequest = new Object();
					if (url.indexOf("?") != -1) {
						var str = url.substr(1);
						strs = str.split("&");
						for (var i = 0; i < strs.length; i++) {
							theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
						}
					}
					return theRequest;
				}
				var url = location.href;
				var obj = GetRequest(url);
				imgurl = obj.position;
				$("#chosedImage").attr('src', imgurl);
			});
			function upload(nwaiting) {
				var url = get_url() + 'signUp/create/' + phoneNum;
				var activityNameS = $('#activityName').val();
				if (activityNameS != "") {
					var data = JSON.stringify(picture);
					//var mapData = {};
					var activityName = changeSymbol(eval(document.getElementById('activityName')).value);
					var locationAddr = changeSymbol(address);
					var locationDetail = changeSymbol(eval(document.getElementById('locationDetail')).value);
					var note = changeSymbol((document.getElementById('note')).value);
					var players = changeSymbol((document.getElementById('players')).value);
					var imgName = changeSymbol(name);
					var longitude = lon;
					var latitude = lat;
					//alert( document.getElementById('activityName').value);
					$.ajax({
						method: "post",
						url: url,
						dataType: 'html', //加入这个选项即可
						data: {
							'base64': data,
							'activityName': activityName,
							'locationAddr': locationAddr,
							'locationDetail': locationDetail,
							'note': note,
							'imgName': imgName,
							'longitude': longitude,
							'latitude': latitude,
							'players':players,
							'userType': 'lawyer'
						},
						success: function(json) {
							
							mui.toast("操作成功");
							location.href = "my_welfare.html";
						},
						error: function(jqXHR, textStatus, errorThrown) {
							//console.log(textStatus);
							alert('error1111');
						},
						complete: function() {
							nwaiting.close();
						}
					});
				} else {
					mui.toast("活动名称不能为空！");
					nwaiting.close();
				}
			}

			function compress(url) {
				// 兼容以“file:”开头的情况
				picture.splice(0,picture.length);
				if (url != null) {
					if (0 != url.toString().indexOf("file://")) {
						url = "file://" + url;
					}
					//var _div_ = $(".showimg")[0];
					var _img_ = new Image();
					_img_.src = url; // 传过来的图片路径在这里用。
					_img_.onclick = function() {
						plus.runtime.openFile(url);
					};
					_img_.onload = function() {
						var tmph = _img_.height;
						var tmpw = _img_.width;
						var isHengTu = tmpw > tmph;
						var max = Math.max(tmpw,
							tmph);
						var min = Math.min(tmpw,
							tmph);
						var bili = min / max;
						if (max > 1200) {
							max = 1200;
							min = Math.floor(bili * max);
						}
						tmph = isHengTu ? min : max;
						tmpw = isHengTu ? max : min;
						_img_.style.border = "1px solid rgb(200,199,204)";
						_img_.style.margin = "10px";
						_img_.style.width = "300px";
						_img_.style.height = "380px";
						_img_.onload = null;
						var nwaiting = plus.nativeUI.showWaiting(); //显示原生等待框
						plus.io.resolveLocalFileSystemURL(url, function(entry) {
								entry.file(function(file) {
									name = file.name;
									canvasResize(file, {
										width: tmpw,
										height: tmph,
										crop: false,
										quality: 50, //压缩质量
										rotate: 0,
										callback: function(data, width, height) {
											picture.push(data);
											upload(nwaiting);
											_img_.src = data;
										}
									});
								});
							},
							function(e) {
								console.log(e.message);
							}
						);
					};
				}
			};
			function getGEO_status() {
				var wid = '';
				wid = plus.geolocation.getCurrentPosition(function(p) {
					//mui.toast("成功定位！");
					getLocation();
					/*alert( "Geolocation\nLatitude:" + p.coords.latitude + "\nLongitude:" + p.coords.longitude + "\nAltitude:" + p.coords.altitude );*/
				}, function(e) {
					mui.toast("定位失败！请开启GPS！");
					/*alert( "Geolocation error: " + e.message );*/
				});
			}

			function supportsGeoLocation() {
				return !!navigator.geolocation;
			}

			function getLocation() {
				//navigator.geolocation.getCurrentPosition(mapIt, locationError);
				plus.geolocation.getCurrentPosition(function(p) {
					//	transform(p.coords.longitude, p.coords.latitude);
					marker = new BMap.Marker(new BMap.Point(p.coords.longitude, p.coords.latitude));
					//bmap.addOverlay(marker);
					marketFirst = false;
					//bmap.setCenter(new BMap.Point(p.coords.longitude, p.coords.latitude));
					mapIt(p);
				}, function(e) {
					alert("定位失败！");
				}, {
					provider: 'baidu'
				});
			} //定位成功时，执行的函数
			function mapIt(position) {
				lon = position.coords.longitude;
				lat = position.coords.latitude;
				//alert("您位置的经度是："+lon+" 纬度是："+lat);
				var map = new BMap.Map("allmap");
				var point = new BMap.Point("" + lon + "",
					"" + lat + "");
				map.centerAndZoom(point,
					19);
				var gc = new BMap.Geocoder();
				// BMap.Convertor.translate(point,0,translateCallback); 
				//translateCallback(point);
				var marker = new BMap.Marker(point);
				map.addOverlay(marker);
				map.setCenter(point);
				gc.getLocation(point,
					function(rs) {
						var addComp = rs.addressComponents;
						if (addComp.province !== addComp.city) {
							address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
						} else {
							address = addComp.city + addComp.district + addComp.street + addComp.streetNumber;
						}
						if (address != null) {
							//alert(address);
							mui.toast("成功定位！");
							$("#myAddress").html(address);
						}
					}
				);
			}
			
			function locationError(error) {
				switch (error.code) {
					case error.PERMISSION_DENIED:
						mui.toast("User denied the request for Geolocation.");
						break;
					case error.POSITION_UNAVAILABLE:
						mui.toast("Location information is unavailable.");
						break;
					case error.TIMEOUT:
						mui.toast("The request to get user location timed out.");
						break;
					case error.UNKNOWN_ERROR:
						mui.toast("An unknown error occurred.");
						break;
				}
			}
			$('input').focus(function() {
				$('.footer1').fadeOut(0);
			});
			$('input').blur(function() {
				$('.footer1').fadeIn(0);
			});
			$(function() {
				$("#activityName").blur(function(){
					if($(this).val()==""){
						mui.toast("请输入活动名称");
						$(this).focus();
					}
				});
				$("#locationDetail").blur(function(){
					if($(this).val()==""){
						mui.toast("请输入位置明细");
						$(this).focus();
					}
				});
				$("#players").blur(function(){
					if($(this).val()==""){
						mui.toast("请输入活动人数");
						$(this).focus();
					}
				});
				if($("#note").val() == null || $("#note").val() == ""){
					$("#note").val("");
				}
				
				$('#back').click(function() {
					history.go(-1);
				})
			});
		</script>
	</body>

</html>